﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;
using System.Data;
using DevExpress.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Models;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 通用弹出选择框
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class DialogController : AdminBaseController
    {
        //
        // GET: /Admin/Dialog/

        /// <summary>
        /// 部门逻辑类
        /// </summary>
        private BLL.HRDept hrDeptBLL = new BLL.HRDept();
        /// <summary>
        /// 岗位逻辑类
        /// </summary>
        private BLL.HRPosition hrPositionBLL = new BLL.HRPosition();
        /// <summary>
        /// 人员岗位逻辑类
        /// </summary>
        private BLL.HREmplPosition hrEmplPositionBLL = new BLL.HREmplPosition();
        /// <summary>
        /// 工作组逻辑类
        /// </summary>
        private BLL.HRWorkGrp hrWorkGrpBLL = new BLL.HRWorkGrp();
        /// <summary>
        /// 用户组逻辑类
        /// </summary>
        private BLL.PrvGroup prvGroupBLL = new BLL.PrvGroup();
        /// <summary>
        /// 工作组人员逻辑类
        /// </summary>
        private BLL.HRWorkGrpMember hrWorkGrpMemberBLL = new BLL.HRWorkGrpMember();
        /// <summary>
        /// 信息类别逻辑类
        /// </summary>
        private BLL.DocCls docClsBLL = new BLL.DocCls();
        /// <summary>
        /// 信息逻辑类
        /// </summary>
        private BLL.Document documentBLL = new BLL.Document();
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 选择部门
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult DeptChooseTree()
        {
            return BindDeptTreeData("DeptChooseTree");
        }
        /// <summary>
        /// 选择岗位
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult PositionChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            List<Model.HRPosition> hrPositionList = hrPositionBLL.GetListByEntityNo(entityNo);
            return BindDeptTreeData("PositionChooseTree", hrPositionList);
        }
        /// <summary>
        /// 选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult EmpChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            return BindDeptTreeData("EmpChooseTree", null, emplDT);
        }

        /// <summary>
        /// 选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult ChkDocHighEnrolEmpTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "1");
        }

        public ActionResult OfficeItemManagerDialog(string itemClsNo)
        {
            if (itemClsNo == null)
            {
                ViewData["itemClsNo"] = "00";
            }
            else
            {
                ViewData["itemClsNo"] = itemClsNo;
            }

            List<Model.ItemCls> itemClsModel = CommonCode.GetItemList(GlobalConstant.ENTITYNO);
            List<SelectListItem> list = new List<SelectListItem>();
            SelectListItem item = new SelectListItem();
            item.Text = "全部";
            item.Value = "00";
            list.Add(item);
            foreach (Model.ItemCls itemCls in itemClsModel)
            {
                item = new SelectListItem();
                item.Text = itemCls.FItemClsName;
                item.Value = itemCls.FItemClsNo;
                list.Add(item);
            }

            ViewData["clsNoList"] = list;

            int pageIndex = 1;
            List<Model.Item> itemList = GetItemList(itemClsNo, pageIndex);

            return View(itemList);
        }

        public ActionResult OfficeItemManagerDialogPartial()
        {

            int pageIndex = Request.Params["pageIndex"] == null ? 0 : int.Parse(Request.Params["pageIndex"].ToString());
            int pageCount = Request.Params["PageCount"] == null ? 0 : int.Parse(Request.Params["PageCount"].ToString());
            int pageRowSize = Request.Params["pageRowSize"] == null ? 0 : int.Parse(Request.Params["pageRowSize"].ToString());
            int pageRowCount = Request.Params["pageRowCount"] == null ? 0 : int.Parse(Request.Params["pageRowCount"].ToString());
            string callbackArg = DevExpressHelper.CallbackArgument;
            string command = Request.Params["command"] == null ? "" : Request.Params["command"].ToString();

            string itemClsNo = Request.Params["itemClsNo"];

            if (command == "PAGERONCLICK")
            {
                string[] args = callbackArg.Split(new char[1] { '|' });
                string arg = args[args.Count() - 1];

                switch (arg)
                {
                    case "PBN;":
                        {
                            //下一页
                            pageIndex = pageIndex + 2;
                            break;
                        }
                    case "PBP;":
                        {
                            //上一页
                            //pageIndex = pageIndex;
                            break;
                        }
                    case "PBL;":
                        {
                            //最后一页
                            pageIndex = pageCount;
                            break;
                        }
                    case "PBF;":
                        {
                            //第一页
                            pageIndex = 1;
                            break;
                        }
                    default:
                        {
                            //点击数字页码
                            string tempIndex = arg.Replace("PN", "");
                            tempIndex = tempIndex.Replace(";", "");
                            if (RegExp.IsNumeric(tempIndex))
                            {
                                pageIndex = int.Parse(tempIndex) + 1;
                            }
                            break;
                        }

                }
            }
            else
            {
                pageIndex = pageIndex + 1;
            }


            List<Model.Item> itemList = GetItemList(itemClsNo, pageIndex, pageCount, pageRowSize);


            return PartialView("OfficeItemManagerDialogPartial", itemList);
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageCount">每页显示大小</param>
        /// <param name="pageRowSize">每页显示页数</param>
        /// <returns>集合</returns>
        private List<Model.Item> GetItemList(string itemClsNo, int pageIndex, int pageCount = 0, int pageRowSize = 0)
        {
            BLL.Item itemBll = new BLL.Item();

            BLL.Common commonBll = new BLL.Common();
            string fiedls = "*";
            int total;
            string where = "";
            if (itemClsNo != null)
            {
                if (itemClsNo == "00")
                {
                    where = "";
                }
                else
                {
                    where = " FItemClsNo= " + itemClsNo;
                }
            }

            DataSet ds = commonBll.GetListByPage("dbo.v_Item_Cls", fiedls, Common.GlobalConstant.CONSTRING_PAGESIZE, pageIndex, where, "FItemNo", 0, out total);

            List<Model.Item> itemAllList = new List<Model.Item>();
            List<Model.Item> itemList = itemBll.DataTableToListItem(ds.Tables[0]);

            pageRowSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            for (int i = 0; i < total; i++)
            {
                itemAllList.Add(null);
            }
            for (int i = 0; i < pageRowSize; i++)
            {
                if (itemList.Count > i)
                {
                    itemAllList[((pageIndex - 1) * pageRowSize) + i] = itemList[i];
                }
            }

            return itemAllList;
        }

        /// <summary>
        /// 选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult EmpLeaveTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            if (OperateSession.get(Common.GlobalConstant.PARAM_LOGINID) == "admin")
            {
                HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            }
            else
            {
                HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "FDeptNo='" + OperateSession.get(Common.GlobalConstant.PARAM_DEPTNO) + "'");
            }
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "1", true, HRDeptList);
        }
        /// <summary>
        /// 选择人员(补录人员去向)
        /// </summary>
        /// <returns></returns>
        public ActionResult EmpLeaveAdditionTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "1", true, HRDeptList);
        }
        /// <summary>
        /// 信息查询选择工作组
        /// </summary>
        /// <returns></returns>
        public ActionResult DocQueryWorkGroupChooseTree()
        {
            return BindWorkGroupChooseData(null, "1", false);
        }
        /// <summary>
        /// 信息查询选择部门
        /// </summary>
        /// <returns></returns>
        public ActionResult DocQueryDeptChooseTree()
        {
            return BindDeptTreeData("DeptChooseTree", null, null, "1", false);
        }
        /// <summary>
        /// 信息查询选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult DocQueryEmpChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "1", false);
        }

        /// <summary>
        /// 信息查询选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult PeerReviewBeenVoterChooseTree(string beenVoterClsCd)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.PeerReviewBeenVoter PeerReviewBeenVoterBLL = new BLL.PeerReviewBeenVoter();
            DataTable emplDT = PeerReviewBeenVoterBLL.GetAllList(entityNo, beenVoterClsCd);

            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);
        }
        /// <summary>
        /// 评议人信息查询选择人员
        /// </summary>
        /// <returns></returns>
        public ActionResult PeerReviewVoterChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.PeerReviewVoter peerReviewVoterBll = new BLL.PeerReviewVoter();
            DataTable emplDT = peerReviewVoterBll.GetAllListTable(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");

            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);

        }
        /// <summary>
        /// 网上考勤人员选择及定义
        /// </summary>
        /// <returns></returns>
        public ActionResult AttndanceDefinedChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.AttendanceDefined attendanceDefinedBLL = new BLL.AttendanceDefined();
            DataTable emplDT = attendanceDefinedBLL.GetAllListTable(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);
        }
        /// <summary>
        /// 绩效人员选择及定义
        /// </summary>
        /// <returns></returns>
        public ActionResult Performanced()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.AttendanceDefined attendanceDefinedBLL = new BLL.AttendanceDefined();
            DataTable emplDT = attendanceDefinedBLL.GetAllListTable(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);
        }

        /// <summary>
        /// 参与去向管理人员定义
        /// </summary>
        /// <returns></returns>
        public ActionResult AllowPerformanced()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.AttendanceDefined attendanceDefinedBLL = new BLL.AttendanceDefined();
            DataTable emplDT = attendanceDefinedBLL.GetAllListTable(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);
        }

        /// <summary>
        /// 允许补录其他人员绩效台账人员定义
        /// </summary>
        /// <returns></returns>
        public ActionResult LeavePerson()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            BLL.AttendanceDefined attendanceDefinedBLL = new BLL.AttendanceDefined();
            DataTable emplDT = attendanceDefinedBLL.GetAllListTable(entityNo);
            List<Model.HRDept> HRDeptList = new List<Model.HRDept>();
            HRDeptList = hrDeptBLL.GetListBYFIsAgency(entityNo, "");
            return BindDeptTreeData("EmpChooseTree", null, emplDT, "3", true, HRDeptList);
        }

        /// <summary>
        /// 选择工作组
        /// </summary>
        /// <returns></returns>
        public ActionResult WorkGroupChooseTree()
        {
            return BindWorkGroupChooseData();
        }
        /// <summary>
        /// 选择用户组
        /// </summary>
        /// <returns></returns>
        public ActionResult UserGroupChooseTree()
        {
            return BindUserGroupChooseData();
        }
        /// <summary>
        /// 选择通知对象
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult DocRecObjectChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            BindDeptTreeData("DocRecObjectChooseTree", null, emplDT);
            ViewData["deptEmptreeJsonStr"] = ViewData["treeJsonStr"];

            emplDT = hrWorkGrpMemberBLL.GetWorkGrpEmplNoSByView(entityNo);
            BindWorkGroupChooseData(emplDT);
            ViewData["workGroupEmptreeJsonStr"] = ViewData["treeJsonStr"];
            return View();
        }
        /// <summary>
        /// 合发部门人员选择
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult JoinDeptUserChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            DataTable emplDT = hrEmplPositionBLL.GetMainDeptEmplALL(entityNo);
            return BindDeptTreeData("JoinDeptUserChooseTree", null, emplDT);
        }
        /// <summary>
        /// 信息查询条件选择
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult DocQueryConditionChoose()
        {
            return BindDocQueryConditionData();
        }
        /// <summary>
        /// 信息类别选择(信息维护)
        /// </summary>
        /// <returns></returns>
        public ActionResult DocTransferClsChooseManage(decimal docId)
        {
            ViewData["docId"] = docId;
            return BindDocTransferClsChooseManageData(docId, "1", false);

        }
        /// <summary>
        /// 信息类别选择
        /// </summary>
        /// <returns></returns>
        public ActionResult DocClsChooseTree()
        {
            return BindDocClsChooseData();
        }
        public ActionResult DocClsChooseTreeExt(string selectMode, string checkboxMode)
        {
            return BindDocClsChooseData(selectMode, bool.Parse(checkboxMode));
        }
        /// <summary>
        /// 呈送信息类别选择
        /// </summary>
        /// <returns></returns>
        public ActionResult DocReferenceClsChoose()
        {
            return BindDocReferenceClsChooseData();
        }

        /// <summary>
        /// 绑定信息类别选择数据(信息呈送)
        /// </summary>
        /// <param name="docId">信息编号</param>
        /// <returns></returns>
        private ActionResult BindDocReferenceClsChooseData(string selectMode = "3", bool checkboxMode = true)
        {
            string treeJsonStr = "";
            treeJsonStr += "[";

            string loginName = OperateSession.get(GlobalConstant.PARAM_USERNAME);
            //获取部门信息
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
            string entityNo = GlobalConstant.ENTITYNO;
            if (emplNo != "" && deptNo != "" && entityNo != "")
            {
                List<Model.DocCls> docClsList = new List<Model.DocCls>();
                DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, emplNo, deptNo, "PUB");
                for (int i = 0; i < authorityDT.Rows.Count; i++)
                {
                    DataRow dr = authorityDT.Rows[i];
                    Model.DocCls docClsModel = new Model.DocCls()
                    {
                        FDocClsCd = dr["Fdocclscd"].ToString(),
                        FPreDocClsCd = dr["fpredocclscd"].ToString(),
                        FDocClsProp = dr["fdocclsprop"].ToString(),
                        FDocClsName = dr["fdocclsname"].ToString(),
                        IsAuthority = dr["fisauthority"].ToString(),
                        FSeq = dr["FSeq"] == null ? 0 : int.Parse(dr["FSeq"].ToString())
                    };
                    docClsList.Add(docClsModel);
                }
                if (docClsList.Count > 0)
                {
                    List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                          where m.FPreDocClsCd == ""
                                                          select m).OrderBy(s => s.FSeq).ToList();

                    foreach (Model.DocCls docClsModel in docClsFirstList)
                    {
                        List<Model.DocCls> tmpModelList = (from m in docClsList
                                                           where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                           select m).OrderBy(s => s.FSeq).ToList();

                        int childCount = tmpModelList.Count;
                        if (childCount > 0)
                        {
                            treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':true,'activate':true,'icon':''";
                            treeJsonStr += ",'children':[";
                            GetChildDocClsList(tmpModelList, docClsList, ref treeJsonStr);

                            treeJsonStr += "]";


                        }
                        else
                        {
                            treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':false,'activate':true,'icon':''";

                        }
                        treeJsonStr += "},";
                    }

                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                treeJsonStr += "]";
                treeJsonStr = treeJsonStr.Replace("\\", "");
                treeJsonStr = treeJsonStr.Replace("'", "\"");
                ViewData["treeJsonStr"] = treeJsonStr;
                ViewData["treeSelectMode"] = selectMode;
                ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
                return View("DocReferenceClsChoose");
            }
            else
            {
                return null;
            }
        }
        BLL.FTP_New ftpBLL = new BLL.FTP_New();

        /// <summary>
        /// 上传下载栏目选择
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult EnterpriseFTPChooseTree()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            return BindEnterpriseFTPTreeData("EnterpriseFTPChooseTree");
        }

        #region 文件上传
        BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
        /// <summary>
        /// 绑定上传下载栏目
        /// </summary>
        /// <param name="hrPositionList">岗位列表，如果等于NULL 则部门下面挂岗位</param>
        /// <param name="selectMode">树选择模式</param>
        /// <returns>视图</returns>
        private ActionResult BindEnterpriseFTPTreeData(string viewName, string selectMode = "1", bool checkboxMode = true)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            string treeJsonStr = "";

            string strWhere = " FType='D' ";
            string logId = OperateSession.get(Common.GlobalConstant.PARAM_LOGINID);
            string deptNo = OperateSession.get(Common.GlobalConstant.PARAM_DEPTNO);
            string IsAgency = "N";//是否派出机构
            //是否派出机构
            BLL.PrvUser userBLL = new BLL.PrvUser();
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            string deptno = "";
            string deptnname = "";
            DataSet ds = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entityNo);
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["FIsMainPosition"].ToString() == "Y")
                    {
                        ViewData["EmpName"] = dt.Rows[i]["FEmpName"].ToString();
                        ViewData["DeptName"] = dt.Rows[i]["FDeptName"].ToString();
                        deptno = dt.Rows[i]["FDeptNo"].ToString();
                        deptnname = ViewData["DeptName"].ToString();
                        break;
                    }

                }

            }
            //如果是市局
            Model.HRDept mdept = hrDeptBLL.GetModel(entityNo, deptno);
            //是否派出机构
            if (mdept.FIsAgency == "Y")
            {
                IsAgency = "Y";
            }
            else
            {
                IsAgency = "N";
            }
            BLL.FTP ftpbll = new BLL.FTP();
            if (!ftpbll.FIsAllowLookFtpByEmpNo(emplNo, entityNo))
            {
                //无全局下载权限
                strWhere += " AND FIsUpload='Y' AND FIsDownload='N' ";
            }
            else
            {
                ViewData["isall"] = true;
            }
            ////派出机构只能到 上传的文件夹
            ////市局只能到 下载的文件夹
            //if (IsAgency == "Y")
            //{
            //    strWhere += " AND FIsUpload='Y' AND FIsDownload='N' ";
            //}
            //else
            //{
            //    strWhere += " AND FIsUpload='N' AND FIsDownload='Y' ";
            //}

            List<Model.FTP_New> ftpAllList = ftpBLL.GetModelList(strWhere);//所有栏目
            List<Model.FTP_New> EnterpriseFTPList = new List<Model.FTP_New>();

            if (OperateSession.get(GlobalConstant.PARAM_LOGINID) != "admin")//判断权限
            {
                EnterpriseFTPList = ftpBLL.GetModelList(strWhere);
            }
            else
            {
                EnterpriseFTPList = ftpAllList;
            }

            treeJsonStr += "[";
            treeJsonStr += "{'title':'上传','key':'','expand':true,'isFolder':false,'activate':true,'icon':'" +Url.Content("~/Content/FunctionImages/m_Document.png")  + "','children':[";
            List<Model.FTP_New> PreFtpList = (from c in EnterpriseFTPList
                                              where c.FParentID == null & c.FIsArchive == "N" & c.FIsUpload == "Y"
                                              select c).ToList();
            if (PreFtpList.Count > 0)
            {
                foreach (Model.FTP_New preFtpModel in PreFtpList)
                {
                    List<Model.FTP_New> ftpList = (from c in EnterpriseFTPList
                                                   where c.FParentID == preFtpModel.FID
                                                   select c).ToList();
                    if (ftpList.Count > 0)
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                        BindChildEnterpriseFTPTree(ftpList, EnterpriseFTPList, ref treeJsonStr);
                    }
                    else
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                    }

                    treeJsonStr += "},";
                }

                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            }
            treeJsonStr += "]},";

            treeJsonStr += "{'title':'下载','key':'','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/FunctionImages/m_Document.png") + "','children':[";
            List<Model.FTP_New> PreFtpListdownload = (from c in EnterpriseFTPList
                                                      where c.FParentID == null & c.FIsArchive == "N" & c.FIsDownload == "Y"
                                                      select c).ToList();
            if (PreFtpListdownload.Count > 0)
            {
                foreach (Model.FTP_New preFtpModel in PreFtpListdownload)
                {
                    List<Model.FTP_New> ftpList = (from c in EnterpriseFTPList
                                                   where c.FParentID == preFtpModel.FID
                                                   select c).ToList();
                    if (ftpList.Count > 0)
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                        BindChildEnterpriseFTPTree(ftpList, EnterpriseFTPList, ref treeJsonStr);
                    }
                    else
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                    }

                    treeJsonStr += "},";

                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));


            }
            treeJsonStr += "]},";
            treeJsonStr += "{'title':'归档目录','key':'','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/FunctionImages/m_Document.png") + "','children':[";
            List<Model.FTP_New> PreFtpList2 = (from c in EnterpriseFTPList
                                               where c.FParentID == null & c.FIsArchive == "Y" & c.FIsUpload == "Y"
                                               select c).ToList();


            treeJsonStr += "{'title':'上传','key':'','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/FunctionImages/m_Document.png") + "','children':[";
            if (PreFtpList2.Count > 0)
            {
                
                foreach (Model.FTP_New preFtpModel in PreFtpList2)
                {
                    List<Model.FTP_New> ftpList = (from c in EnterpriseFTPList
                                                   where c.FParentID == preFtpModel.FID
                                                   select c).ToList();

                    if (ftpList.Count > 0)
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                        BindChildEnterpriseFTPTree(ftpList, EnterpriseFTPList, ref treeJsonStr);
                    }
                    else
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                    }

                    treeJsonStr += "},";

                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));

              
            }
            treeJsonStr += "]},";
            List<Model.FTP_New> PreFtpList2download = (from c in EnterpriseFTPList
                                               where c.FParentID == null & c.FIsArchive == "Y" & c.FIsDownload == "Y"
                                               select c).ToList();
            treeJsonStr += "{'title':'下载','key':'','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/FunctionImages/m_Document.png") + "','children':[";
            if (PreFtpList2download.Count > 0)
            {
               
                foreach (Model.FTP_New preFtpModel in PreFtpList2download)
                {
                    List<Model.FTP_New> ftpList = (from c in EnterpriseFTPList
                                                   where c.FParentID == preFtpModel.FID
                                                   select c).ToList();

                    if (ftpList.Count > 0)
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                        BindChildEnterpriseFTPTree(ftpList, EnterpriseFTPList, ref treeJsonStr);
                    }
                    else
                    {
                        treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                    }

                    treeJsonStr += "},";

                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));

               
            }
            treeJsonStr += "]}";
            treeJsonStr += "]}";
            treeJsonStr += "]";


            treeJsonStr = treeJsonStr.Replace("\\", "");
            treeJsonStr = treeJsonStr.Replace("'", "\"");
            ViewData["treeJsonStr"] = treeJsonStr;
            ViewData["treeSelectMode"] = selectMode;
            ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
            return View(viewName);
        }
        /// <summary>
        /// 绑定上传下载栏目子节点
        /// </summary>
        /// <param name="preDirId"></param>
        /// <param name="accManagerDirList"></param>
        /// <param name="treeJsonStr"></param>
        private void BindChildEnterpriseFTPTree(List<Model.FTP_New> preFtpList, List<Model.FTP_New> EnterpriseFTPList, ref string treeJsonStr)
        {
            treeJsonStr += ",'children':[";
            foreach (Model.FTP_New preFtpModel in preFtpList)
            {

                List<Model.FTP_New> ftpList = (from c in EnterpriseFTPList
                                               where c.FParentID == preFtpModel.FID
                                               select c).ToList();
                if (ftpList.Count > 0)
                {
                    treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                    BindChildEnterpriseFTPTree(ftpList, EnterpriseFTPList, ref treeJsonStr);
                }
                else
                {
                    treeJsonStr += "{'title':'" + preFtpModel.FName + "','key':'" + preFtpModel.FID + "','expand':true,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/button_folder.gif") + "'";
                }
                treeJsonStr += "},";
            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            treeJsonStr += "]";
        }
        #endregion
        /// <summary>
        /// 绑定信息类别选择数据
        /// </summary>
        /// <returns>视图</returns>
        private ActionResult BindDocClsChooseData(string selectMode = "3", bool checkboxMode = true)
        {

            string treeJsonStr = "";
            treeJsonStr += "[";
            List<Model.DocCls> docClsList= docClsBLL.GetListIsUseByEntityNo(GlobalConstant.ENTITYNO);

            if (docClsList.Count > 0)
            {
                List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                      where m.FPreDocClsCd == ""
                                                      select m).ToList();

                foreach (Model.DocCls docClsModel in docClsFirstList)
                {
                    List<Model.DocCls> tmpModelList = (from m in docClsList
                                                       where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                       select m).ToList();

                    int childCount = tmpModelList.Count;
                    if (childCount > 0)
                    {
                        treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':false,'isFolder':true,'activate':true,'icon':''";
                        treeJsonStr += ",'children':[";
                        GetChildDocClsList(tmpModelList, docClsList, ref treeJsonStr);

                        treeJsonStr += "]";


                    }
                    else
                    {
                        treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':false,'isFolder':false,'activate':true,'icon':''";

                    }
                    treeJsonStr += "},";
                }

            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            treeJsonStr += "]";
            treeJsonStr = treeJsonStr.Replace("\\", "");
            treeJsonStr = treeJsonStr.Replace("'", "\"");
            ViewData["treeJsonStr"] = treeJsonStr;
            ViewData["treeSelectMode"] = selectMode;
            ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
            return View("DocClsChooseTree");
        }

        /// <summary>
        /// 绑定信息类别选择数据
        /// </summary>
        /// <param name="docId">信息编号</param>
        /// <returns></returns>
        private ActionResult BindDocTransferClsChooseManageData(decimal docId, string selectMode = "3", bool checkboxMode = true)
        {
            string treeJsonStr = "";
            treeJsonStr += "[";
            Model.Document documentModel = documentBLL.GetModel(docId);
            if (documentModel != null)
            {
                string deptNo = documentModel.FDeptNo;
                string empNo = documentModel.FEmplNo;
                List<Model.DocCls> docClsList = new List<Model.DocCls>();
                DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, empNo, deptNo, "PUB");
                for (int i = 0; i < authorityDT.Rows.Count; i++)
                {
                    DataRow dr = authorityDT.Rows[i];
                    Model.DocCls docClsModel = new Model.DocCls()
                    {
                        FDocClsCd = dr["Fdocclscd"].ToString(),
                        FPreDocClsCd = dr["fpredocclscd"].ToString(),
                        FDocClsProp = dr["fdocclsprop"].ToString(),
                        FDocClsName = dr["fdocclsname"].ToString(),
                        IsAuthority = dr["fisauthority"].ToString()
                    };
                    docClsList.Add(docClsModel);
                }
                if (docClsList.Count > 0)
                {
                    List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                          where m.FPreDocClsCd == ""
                                                          select m).ToList();

                    foreach (Model.DocCls docClsModel in docClsFirstList)
                    {
                        List<Model.DocCls> tmpModelList = (from m in docClsList
                                                           where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                           select m).ToList();

                        int childCount = tmpModelList.Count;
                        if (childCount > 0)
                        {
                            treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':true,'activate':true,'icon':''";
                            treeJsonStr += ",'children':[";
                            GetChildDocClsList(tmpModelList, docClsList, ref treeJsonStr);

                            treeJsonStr += "]";


                        }
                        else
                        {
                            treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':false,'activate':true,'icon':''";

                        }
                        treeJsonStr += "},";
                    }

                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                treeJsonStr += "]";
                treeJsonStr = treeJsonStr.Replace("\\", "");
                treeJsonStr = treeJsonStr.Replace("'", "\"");
                ViewData["treeJsonStr"] = treeJsonStr;
                ViewData["treeSelectMode"] = selectMode;
                ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
                return View("DocTransferClsChoose");
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 绑定信息查询条件数据
        /// </summary>
        /// <returns>视图</returns>
        private ActionResult BindDocQueryConditionData()
        {
            return View("DocQueryConditionChoose");
        }
        /// <summary>
        /// 绑定工作组数据
        /// </summary>
        /// <param name="emplDT">工作组人员列表，如果等于NULL 则部门下面挂岗位</param>
        /// <returns></returns>
        private ActionResult BindWorkGroupChooseData(DataTable emplDT = null, string selectMode = "3", bool checkboxMode = true)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            string treeJsonStr = "";
            treeJsonStr += "[";
            List<Model.HRWorkGrp> hrWorkGrpList = hrWorkGrpBLL.GetListByEntityNo(entityNo);
            if (hrWorkGrpList.Count > 0)
            {
                treeJsonStr += "{'title':'工作组','key':'-1','expand':true,'isFolder':true,'activate':true";
                treeJsonStr += ",'children':[";
                foreach (Model.HRWorkGrp hrWorkGrpModel in hrWorkGrpList)
                {
                    treeJsonStr += "{'title':'" + hrWorkGrpModel.FWorkGrpName + "','key':'" + hrWorkGrpModel.FWorkGrpNo + "','expand':false,'isFolder':false,'activate':true";
                    //绑定人员
                    if (emplDT != null)
                    {
                        var tmpEmp = (from c in emplDT.AsEnumerable()
                                      where c["FWorkGrpNo"].ToString() == hrWorkGrpModel.FWorkGrpNo
                                      select c);
                        if (tmpEmp.Count() > 0)
                        {
                            DataTable tmpEmplDT = tmpEmp.CopyToDataTable();
                            treeJsonStr += ",'children':[";
                            GetEmpl(tmpEmplDT, ref treeJsonStr);
                            treeJsonStr += "]";
                        }
                    }
                    treeJsonStr += "},";
                    treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                    treeJsonStr += "]";
                }
                treeJsonStr += "},";
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                treeJsonStr += "]";
            }
            else
            {
                treeJsonStr += "]";
            }
            //treeJsonStr += "},";
            //treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            treeJsonStr = treeJsonStr.Replace("\\", "");
            treeJsonStr = treeJsonStr.Replace("'", "\"");
            ViewData["treeJsonStr"] = treeJsonStr;
            ViewData["treeSelectMode"] = selectMode;
            ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
            return View("WorkGroupChooseTree");
        }

        /// <summary>
        /// 绑定用户组数据
        /// </summary>
        /// <returns></returns>
        private ActionResult BindUserGroupChooseData()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            string selectMode = "3";//树选择模式
            string treeJsonStr = "";
            treeJsonStr += "[";
            List<Model.PrvGroup> prvGroupList = prvGroupBLL.GetListByEntityNo(entityNo);
            if (prvGroupList.Count > 0)
            {
                treeJsonStr += "{'title':'用户组','key':'-1','expand':true,'isFolder':true,'activate':true";
                treeJsonStr += ",'children':[";
                foreach (Model.PrvGroup prvGroupModel in prvGroupList)
                {
                    treeJsonStr += "{'title':'" + prvGroupModel.FGroupName + "','key':'" + prvGroupModel.FGroupNo + "','expand':false,'isFolder':false,'activate':true";
                    treeJsonStr += "},";
                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                treeJsonStr += "]";
            }
            treeJsonStr += "},";
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            treeJsonStr += "]";
            treeJsonStr = treeJsonStr.Replace("\\", "");
            treeJsonStr = treeJsonStr.Replace("'", "\"");
            ViewData["treeJsonStr"] = treeJsonStr;
            ViewData["treeSelectMode"] = selectMode;
            return View("UserGroupChooseTree");
        }
        //private ActionResult BindRecObjectChooseData()
        //{

        //}

        /// <summary>
        /// 绑定部门数据
        /// </summary>
        /// <param name="hrPositionList">岗位列表，如果等于NULL 则部门下面挂岗位</param>
        /// <param name="selectMode">树选择模式</param>
        /// <returns>视图</returns>
        private ActionResult BindDeptTreeData(string viewName, List<Model.HRPosition> hrPositionList = null, DataTable emplDT = null, string selectMode = "3", bool checkboxMode = true, List<Model.HRDept> hrDeptList = null)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            string treeJsonStr = "";
            treeJsonStr += "[";
            if (hrDeptList == null)
            {
                hrDeptList = hrDeptBLL.GetListByEntityNo(entityNo);
            }
            if (hrDeptList.Count > 0)
            {
                Dictionary<int, List<Model.HRDept>> dicHRDeptList = new Dictionary<int, List<Model.HRDept>>();
                if (GlobalConstant.ENTITYNO == "05")
                {
                    //鄞州财政
                    //局机关
                    dicHRDeptList.Add(0, hrDeptList.Where(s => s.FIsAgency == "N").OrderBy(s => s.FDeptNo).ToList());
                    //派出机构(镇乡街道)
                    dicHRDeptList.Add(1, hrDeptList.Where(s => s.FIsAgency == "Y").OrderBy(s => s.FDeptNo).ToList());

                }
                else
                {
                    dicHRDeptList.Add(0, hrDeptList);
                }
                foreach (KeyValuePair<int, List<Model.HRDept>> dicDept in dicHRDeptList)
                {
                    if (dicHRDeptList.Count == 1)
                    {
                        treeJsonStr += "{'title':'组织结构','key':'-1','expand':true,'isFolder':true,'activate':true";
                        treeJsonStr += ",'children':[";
                    }
                    else
                    {

                        if (dicDept.Key == 0)
                        {
                            treeJsonStr += "{'title':'局机关','key':'-1','expand':true,'isFolder':true,'activate':true";
                            treeJsonStr += ",'children':[";

                        }
                        else
                        {
                            if (dicDept.Value.Count > 0)
                            {
                                treeJsonStr += "{'title':'镇乡街道','key':'-1','expand':true,'isFolder':true,'activate':true";
                                treeJsonStr += ",'children':[";
                            }
                        }
                    }
                    List<Model.HRDept> keyHRDeptList = dicDept.Value;
                    foreach (Model.HRDept hrDeptModel in keyHRDeptList)
                    {
                        List<Model.HRDept> tmpChildDeptList = keyHRDeptList.Where(s => s.FParentDeptNo == hrDeptModel.FDeptNo).ToList();
                        int childCount = tmpChildDeptList.Count;
                        if (childCount > 0)
                        {
                            treeJsonStr += "{'title':'" + hrDeptModel.FDeptName + "','key':'" + hrDeptModel.FDeptNo + "','expand':false,'isFolder':true,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/dept_Groups.png") + "'";
                            treeJsonStr += ",'children':[";
                            GetChildHRDept(tmpChildDeptList, ref treeJsonStr, keyHRDeptList, hrPositionList, emplDT);
                            //绑定部门
                            if (hrPositionList != null)
                            {
                                List<Model.HRPosition> tmpPositionList = hrPositionList.Where(c => c.FDeptNo == hrDeptModel.FDeptNo).ToList();
                                if (tmpPositionList.Count > 0)
                                {
                                    treeJsonStr += ",";
                                    GetPostion(tmpPositionList, ref treeJsonStr);

                                }
                            }
                            //绑定人员
                            if (emplDT != null)
                            {
                                var tmpEmp = (from c in emplDT.AsEnumerable()
                                              where c["FDeptNo"].ToString() == hrDeptModel.FDeptNo
                                              select c);
                                if (tmpEmp.Count() > 0)
                                {
                                    DataTable tmpEmplDT = tmpEmp.CopyToDataTable();
                                    treeJsonStr += ",";
                                    GetEmpl(tmpEmplDT, ref treeJsonStr);
                                }

                            }
                            treeJsonStr += "]";

                        }
                        else
                        {
                            treeJsonStr += "{'title':'" + hrDeptModel.FDeptName + "','key':'" + hrDeptModel.FDeptNo + "','expand':false,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/dept_Groups.png") + "'";
                            //绑定部门
                            if (hrPositionList != null)
                            {
                                List<Model.HRPosition> tmpPositionList = hrPositionList.Where(c => c.FDeptNo == hrDeptModel.FDeptNo).ToList();
                                if (tmpPositionList.Count > 0)
                                {
                                    treeJsonStr += ",'children':[";
                                    GetPostion(tmpPositionList, ref treeJsonStr);
                                    treeJsonStr += "]";
                                }
                            }
                            //绑定人员
                            if (emplDT != null)
                            {
                                var tmpEmp = (from c in emplDT.AsEnumerable()
                                              where c["FDeptNo"].ToString() == hrDeptModel.FDeptNo
                                              select c);
                                if (tmpEmp.Count() > 0)
                                {
                                    DataTable tmpEmplDT = tmpEmp.CopyToDataTable();
                                    treeJsonStr += ",'children':[";
                                    GetEmpl(tmpEmplDT, ref treeJsonStr);
                                    treeJsonStr += "]";
                                }
                            }

                        }
                        treeJsonStr += "},";
                    }
                    if (keyHRDeptList.Count > 0)
                    {
                        treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                        treeJsonStr += "]";
                        treeJsonStr += "},";
                    }
                }
                treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                treeJsonStr += "]";

            }
            else
            {
                //treeJsonStr += "{'title':'组织结构','key':'-1','expand':true,'isFolder':false,'activate':true";
                treeJsonStr += "]";
            }

            //treeJsonStr += "},";
            //treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
            //treeJsonStr += "]";
            treeJsonStr = treeJsonStr.Replace("\\", "");
            treeJsonStr = treeJsonStr.Replace("'", "\"");
            ViewData["treeJsonStr"] = treeJsonStr;
            ViewData["treeSelectMode"] = selectMode;
            ViewData["checkboxMode"] = checkboxMode.ToString().ToLower();
            return View(viewName);
        }

        /// <summary>
        /// 递归获取子部门
        /// </summary>
        /// <param name="hrDeptChildList">子部门列表</param>
        /// <param name="treeJsonStr">json树的字符串</param>
        /// <param name="hrDeptList">全部部门列表</param>
        /// <param name="emplDT">全部人员DT</param>
        private void GetChildHRDept(List<Model.HRDept> hrDeptChildList, ref string treeJsonStr, List<Model.HRDept> hrDeptList, List<Model.HRPosition> hrPositionList, DataTable emplDT)
        {
            foreach (Model.HRDept tmpDeptModel in hrDeptChildList)
            {
                List<Model.HRDept> tmpChildDeptList = hrDeptList.Where(s => s.FParentDeptNo == tmpDeptModel.FDeptNo).ToList();

                int childCount = tmpChildDeptList.Count;
                if (childCount > 0)
                {
                    treeJsonStr += "{'title':'" + tmpDeptModel.FDeptName + "','key':'" + tmpDeptModel.FDeptNo + "','expand':false,'isFolder':true,'activate':true";
                    treeJsonStr += ",'children':[";
                    GetChildHRDept(tmpChildDeptList, ref treeJsonStr, hrDeptList, hrPositionList, emplDT);
                    //绑定部门
                    if (hrPositionList != null)
                    {
                        List<Model.HRPosition> tmpPositionList = hrPositionList.Where(c => c.FDeptNo == tmpDeptModel.FDeptNo).ToList();
                        if (tmpPositionList.Count > 0)
                        {
                            treeJsonStr += ",";
                            GetPostion(tmpPositionList, ref treeJsonStr);

                        }
                    }
                    //绑定人员
                    if (emplDT != null)
                    {
                        var tmpEmp = (from c in emplDT.AsEnumerable()
                                      where c["FDeptNo"].ToString() == tmpDeptModel.FDeptNo
                                      select c);
                        if (tmpEmp.Count() > 0)
                        {
                            DataTable tmpEmplDT = tmpEmp.CopyToDataTable();
                            treeJsonStr += ",";
                            GetEmpl(tmpEmplDT, ref treeJsonStr);
                        }

                    }
                    treeJsonStr += "]";

                }
                else
                {
                    treeJsonStr += "{'title':'" + tmpDeptModel.FDeptName + "','key':'" + tmpDeptModel.FDeptNo + "','expand':false,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/dept_Groups.png") + "'";
                    //绑定部门
                    if (hrPositionList != null)
                    {
                        List<Model.HRPosition> tmpPositionList = hrPositionList.Where(c => c.FDeptNo == tmpDeptModel.FDeptNo).ToList();
                        if (tmpPositionList.Count > 0)
                        {
                            treeJsonStr += ",'children':[";
                            GetPostion(tmpPositionList, ref treeJsonStr);
                            treeJsonStr += "]";
                        }
                    }
                    //绑定人员
                    if (emplDT != null)
                    {
                        var tmpEmp = (from c in emplDT.AsEnumerable()
                                      where c["FDeptNo"].ToString() == tmpDeptModel.FDeptNo
                                      select c);
                        if (tmpEmp.Count() > 0)
                        {
                            DataTable tmpEmplDT = tmpEmp.CopyToDataTable();
                            treeJsonStr += ",'children':[";
                            GetEmpl(tmpEmplDT, ref treeJsonStr);
                            treeJsonStr += "]";
                        }
                    }

                }
                treeJsonStr += "},";
            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
        }

        /// <summary>
        /// 绑定岗位树岗位数据
        /// </summary>
        /// <param name="hrPositionDeptList">该部门岗位列表</param>
        /// <param name="treeJsonStr">json树的字符串</param>
        private void GetPostion(List<Model.HRPosition> hrPositionDeptList, ref string treeJsonStr)
        {
            foreach (Model.HRPosition hrPositionModel in hrPositionDeptList)
            {
                treeJsonStr += "{'title':'" + hrPositionModel.FPositionName + "','key':'" + hrPositionModel.FPositionNo + "','expand':false,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/mail_post_to.png") + "','addClass':'position'";
                treeJsonStr += "},";
            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
        }
        /// <summary>
        /// 绑定人员树数据
        /// </summary>
        /// <param name="emplDeptDT">该部门人员DT</param>
        /// <param name="treeJsonStr">json树的字符串</param>
        private void GetEmpl(DataTable emplDeptDT, ref string treeJsonStr)
        {
            foreach (DataRow dr in emplDeptDT.Rows)
            {
                treeJsonStr += "{'title':'" + dr["FEmpName"].ToString() + "','key':'" + dr["FEmplNo"].ToString() + "','expand':false,'isFolder':false,'activate':true,'icon':'" + Url.Content("~/Content/ControlImages/user_male.png") + "','addClass':'user'";
                treeJsonStr += "},";
            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
        }
        /// <summary>
        /// 递归获取栏目树
        /// </summary>
        /// <param name="docClsChildList"></param>
        /// <param name="docClsList"></param>
        /// <param name="treeJsonStr"></param>
        private void GetChildDocClsList(List<Model.DocCls> docClsChildList, List<Model.DocCls> docClsList, ref string treeJsonStr)
        {
            foreach (Model.DocCls docClsModel in docClsChildList)
            {
                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                   select m).OrderBy(s => s.FSeq).ToList();

                int childCount = tmpModelList.Count;
                if (childCount > 0)
                {
                    treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':true,'activate':true,'icon':''";
                    treeJsonStr += ",'children':[";
                    GetChildDocClsList(tmpModelList, docClsList, ref treeJsonStr);

                    treeJsonStr += "]";
                }
                else
                {
                    treeJsonStr += "{'title':'" + docClsModel.FDocClsName + "','key':'" + docClsModel.FDocClsCd + "','expand':true,'isFolder':false,'activate':true,'icon':''";

                }
                treeJsonStr += "},";
            }
            treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
        }
    }
}
